import request from '@/utils/request'
import type { IRegister, ILogin, IUserInfo, UpdatePasswordParams } from './types'

// 注册
export const userRegisterService = ({ username, password, repassword }: IRegister) =>
  request.post('/api/reg', { username, password, repassword })

// 登陆
export const userLoginService = ({ username, password }: ILogin) =>
  request.post('/api/login', { username, password })

// 获取用户信息
export const userGetInfoService = () => request.get('/my/userinfo')

// 更改基本资料
export const userUpdateInfoService = (data: IUserInfo) => request.put('/my/userinfo', data)

// 更改用户头像
export const userUpdateAvatarService = (avatar: string) =>
  request.patch('/my/update/avatar', { avatar })

// 更新密码
export const userUpdatePassService = ({ old_pwd, new_pwd, re_pwd }: UpdatePasswordParams) =>
  request.patch('/my/updatepwd', { old_pwd, new_pwd, re_pwd })
